package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import javafx.beans.binding.ObjectExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/travel")
public class TravelController {
    @Autowired
    private ITravelService travelService;

    @RequestMapping("list")
    public String list(Model m,@ModelAttribute("qo")TravelQueryObject qo){
        if (qo.getState() == null) {
            qo.setState(Travel.TRAVEL_AUDIT);
        }
        qo.setOrderBy("t.lastUpdateTime");
        m.addAttribute("pageInfo",travelService.queryForWait(qo));
        return "/travel/list";
    }

    @RequestMapping("changeState")
    @ResponseBody
    public Object changeState(Travel travel){
        travelService.changeState(travel);
        return new JSONResult();
    }

    @RequestMapping("getContent")
    @ResponseBody
    public Object getContent(Long id){
        return travelService.getContent(id);
    }


    @RequestMapping("queryByStrategyId")
    public String queryByStrategyId(Model m,@ModelAttribute("qo")TravelQueryObject qo){
        m.addAttribute("pageInfo",travelService.queryForWait(qo));
        return "/travel/list";
    }


}
